package cz.spock.core.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import cz.spock.core.dao.CoreDao;
import cz.spock.core.entity.security.AccountSecurity;

@Component
public class SpringSecurityService implements UserDetailsService {

    @Autowired
    private CoreDao core;
    
    @Override
    public UserDetails loadUserByUsername(String login) throws UsernameNotFoundException, DataAccessException {
        UserDetails ud = (UserDetails) core.ofy().query(AccountSecurity.class).filter("login", login).get();        
        return ud;
    }

}
